﻿<?php
session_start();
include_once "checkLogin.php";
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="css/menu.css" rel="stylesheet" type="text/css"/>
    <script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="js/nav.js" type="text/javascript"></script>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="js/TweenMax.min.js"></script>
    <link href="css/word.css" rel="stylesheet" type="text/css"/>
    <title>首页</title>
</head>
<body>
<canvas id="Mycanvas" style="position: absolute;left: 0%;width: 100%;height: 99%"></canvas>

<div id="main">
    <header>
        <div id="header1">
            <div id="a"></div>
            <img src="img/logo1.png">
            <h2 class="letter-wrap"  data-stagger="-0.015">清华大学图书馆管理系统</h2>
            <span>当前登录用户：<?php echo $_SESSION['admin']?></span>
        </div>
    </header>
    <div class="navmain">
        <div id="time"><span></span></div>
        <ul id="nav_all">
            <li><a href="index.php">首页</a></li>
            <?php
            include_once "conn.php";
            $main = new main();
            $info = $main->checkAdmin($_SESSION['admin']);
            if ($info['system']){
                ?>
                <li><a href="#">系统设置</a>
                    <ul style="display: none;">
                        <li><a href="library.php">图书馆信息</a></li>
                        <li><a href="admin.php">管理员设置</a></li>
                        <li><a href="#">参数设置</a></li>
                        <li><a href="shujia.php">书架设置</a></li>
                    </ul>
                </li>
            <?php
            }
            if ($info['readerset']){
                ?>
                <li><a href="#">读者管理</a>
                    <ul style="display: none;">
                        <li><a href="readertype.php">读者类型管理</a></li>
                        <li><a href="user.php">读者档案管理</a></li>
                    </ul>
                </li>
            <?php
            }
            if ($info['bookset']){
                ?>
                <li><a href="tushudangan.php">图书档案管理</a></li>
            <?php
            }
            if ($info['book']){
                ?>
                <li><a>图书借还</a>
                    <ul style="display: none;">
                        <li><a href="bookjieyue.php">图书借阅</a></li>
                        <li><a href="bookxujie.php">图书续借</a></li>
                        <li><a href="bookback.php">图书归还</a></li>
                    </ul>
                </li>
            <?php
            }
            if ($info['syschaxun']){
                ?>
                <li> <a>系统查询</a>
                    <ul style="display: none;">
                        <li><a href="tushudanganchaxun.php">图书档案查询</a></li>
                        <li><a href="jieyuechaxun.php">图书借阅查询</a></li>
                        <li><a href="jieyue.php">借阅到期提醒</a></li>
                    </ul>
                </li>
            <?php
            }
            ?>
            <li>
                <a href="pw.php">更改口令</a>
            </li>
            <li><a href="zhuxiao.php">注销</a> </li>
        </ul>
    </div>
    <div id="b"></div>
    <div id="c">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title">
                <li class="layui-this">表格模式</li>
                <li>图表模式</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show"><div id="content">
                        <img src="img/timg.jpg">
                        <div id="text"><i>BookBorrowSoft</i></div>
                        <hr class="layui-bg-green">
                        <table class="layui-table" lay-even lay-skin="line">
                  
                            <thead>
                            <tr>
                                <th>排名</th>
                                <th>图书条形码</th>
                                <th>图书名称</th>
                                <th>图书类型</th>
                                <th>书架</th>
                                <th>出版社</th>
                                <th>作者</th>
                                <th>定价(元)</th>
                                <th>借阅次数</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            include_once "conn.php";
                            $main = new main();
                            $result = $main->IndexRank();
                            for ($i = 0; $i < count($result); $i++) {
                                ?>
                                <tr>
                                    <td> <?php echo $i+1 ?></td>
                                    <td> <?php echo $result[$i]['barcode'] ?></td>
                                    <td> <?php echo $result[$i]['bookname'] ?></td>
                                    <td> <?php echo $result[$i]['type'] ?></td>
                                    <td> <?php echo $result[$i]['name'] ?></td>
                                    <td> <?php echo $result[$i]['chuban'] ?></td>
                                    <td> <?php echo $result[$i]['author'] ?></td>
                                    <td> <?php echo $result[$i]['price'] ?></td>
                                    <td> <?php echo $result[$i]['num'] ?></td>
                                </tr>
                                <?php
                            }
                            ?>
                            </tbody>
                        </table>
                    </div></div>
                <div class="layui-tab-item"><div id="mains" style="width: 600px;height:400px;margin: 8% auto"></div></div>
            </div>

        </div>

    </div>

    <footer>
        <hr id="one">
        <hr id="two">
        CopyRight © 2019 www.cdp.cn.com 清华大学图书馆
    </footer>
</div>
</body>
<script src="layui/layui.js"></script>
<script src="js/echarts.common.min.js"></script>
<script src="js/bg.js"></script>
<script src="js/logo.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.use(['layer', 'form','element'], function () {
        var layer = layui.layer
            , form = layui.form
            ,element = layui.element;
    });
    let myChart = echarts.init(document.getElementById('mains'));
    // 显示标题，图例和空的坐标轴
    let names=[];    //类别数组（实际用来盛放X轴坐标值）
    let nums=[];    //销量数组（实际用来盛放Y坐标值）
    // 异步加载数据
    $.ajax({
        type: "POST",
        url: "getdata.php",
        dataType:'JSON',
        cache: false, //不缓存此页面
        success: function (data) {
            console.log(data);
            for (let i = 0; i < data.length; i++) {
                 names.push(`${data[i].name}`);    //挨个取出类别并填入类别数组
            }
            var option = {
                title : {
                    text: '书架借阅排行',
                    x:'center'
                },
                tooltip : {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient : 'vertical',
                    x : 'left',
                    data:names
                },
                series : [
                    {
                        name:'数量小计',
                        type:'pie',
                        radius : [0, 110],
                        selectedOffset : [10],
                        data: (function(){
                            let res = [];
                            for (let i = 0; i < data.length; i++) {
                                res.push({
                                    name: data[i].name,
                                    value: data[i].num
                                });
                            }
                            return res;
                        })()
                    }
                ]
            };
            myChart.setOption(option);

        }
    });
    //indexdata = {category:['A','B','C'],total:[4,1,1]};

</script>
</html>

